<template>
  <a-modal
    :title="title"
    :width="600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :okText="$t('确定')"
    @cancel="handleCancel"
    :cancelText="$t('关闭')"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">

        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="cardSign"
          required
          :label="$t('钥匙卡密码')">
          <a-input type="password" :placeholder="$t('请输入钥匙卡密码')" v-model="model.cardSign"/>
        </a-form-model-item>

      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
  import md5 from 'md5'
  import pick from 'lodash.pick'
  import {httpAction,postAction} from "@api/manage";

  export default {
    name: 'DictModal',
    data() {
      return {
        value: 1,
        title: '操作',
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        confirmLoading: false,
        validatorRules: {
          cardSign: [{required: true, message: this.$t('请输入钥匙卡密码')}]
        }
      }
    },
    created() {
    },
    methods: {
      // 确定
      handleOk() {
        let that = this
        // 触发表单验证
        that.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            that.model.cardSign = (that.model.cardSign || '').trim()
            postAction("/system/bisSystemCard/verifyKeyCard",{ cardSign: md5(that.model.cardSign) }).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('clearData')
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.confirmLoading = false
              that.close()
            })
          }else{
            return false;
          }
        })
      },
      // 关闭
      handleCancel() {
        this.close()
      },
      close() {
        this.$emit('close')
        this.visible = false
        this.$refs.form.resetFields();
      }
    }
  }
</script>